const {DBHOST,DBPORT,DBNAME} = require('../config');
//导入 mongoose
const mongoose = require('mongoose');
const UserModel = require('./models/UserModel');
const md5 = require('md5');
//连接数据库
let promise = mongoose.connect(`mongodb://${DBHOST}:${DBPORT}/${DBNAME}`)
//暴露
module.exports = promise;

//创建管理员用户
mongoose.connection.on('open', async () => {
  let count = await UserModel.count({uname: 'root'})
  if(count) return;
  UserModel.create({uname: 'root', pwd: md5('root')})
})